home *** CD-ROM | disk | FTP | other *** search
- Path: gate.net!pslfl2-40
- From: bhutto@gate.net (William Hutto)
- Newsgroups: comp.lang.c
- Subject: Re: Q: Terminating program at EOF
- Date: 7 Jan 1996 04:40:33 GMT
- Organization: CyberGate, Inc.
- Message-ID: <4cnis1$1plk@news.gate.net>
- References: <4cn66j$5r0@fnpx20.fnal.gov>
- NNTP-Posting-Host: pslfl2-40.gate.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4cn66j$5r0@fnpx20.fnal.gov>,
- sfield@fnpx20.fnal.gov (Stephen Field) wrote:
- >Hi,
- >
- >I'm writing a program that looks at poorly formatted text files and reformats
- >them to a user-specified line length. The input text file has a blank line
- >between paragraphs and I would like the newly formatted file to also have
- blank
- >lines between paragraphs.
- >
- >I've written a program that does the job, but it doesn't stop when it reaches
- >the end of the file. The program will write out the reformatted file, but it
- >appends a lot of "extra" characters to the end of the file and only stops
- when
- >I break out of it.
- >
- >I have tried this program on many files and it behaves the same. The program
- >is included below and I've got it running on an SGI running IRIX.
- >
- >Any help appreciated.
- >
- >Steve
- >
- >===================================================
- >/* This program reformats a file that is input by the user to not exceed
- > a number of columns that is also input and outputs the reformatted
- file
- > to a file also given by the user at runtime. Lines are broken at
- spaces. */
- >#include <stdio.h>
- >#define MAX_WORD_LENGTH 80 /* max length of word in input */
- >
- >main()
- >{
- > int line_length, /* max length of line in output */
- > curr_line_length = 0, /* # of chars printed so far in curr line */
- > word_length; /* length of current word */
- > char word[ MAX_WORD_LENGTH+1];/* buffer to read word +1 for terminating
- > '\0' */
- > char c_old=' ',c_new=' '; /* check for newlines with chars */
- ^^^^
- Read comp.lang.c FAQ 12.1. An EOF won't fit in a *char*. Change this to *int*.
-
- > while(c_new!=EOF){ /* new method, still doesn't
- work */
- > c_new=fgetc(fptr_read);
-
- The flow of your code is difficult to follow (not using the _standard_ tabbing
- for nested blocks). I would be surprised if anybody would want to spend their
- time looking at it. If you want such generous commenting in your code and you
- don't want to exceed some right margin, I would suggest you put comments on
- separate lines preceding the fragment of code it refers to.
-
- You can get the FAQ from:
- ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c/C-FAQ-list
-
- Bill
-
- "Whatcha got on?...Your mind?"
-